//@charset "utf-8";
// PlateListView 与 FormView 间通信
define(function(require, exports, module) {
	var Backbone = require('backbone');
	var plateListModel = require('../models/platelist');
	var CodeListModel = require('../models/codelist');
	var BaseView = Backbone.View.extend({
		el: '',
		// isMove: false,
		initialize: function() {},
		endDragPlate: function(e) {

			var $dom = $(e.currentTarget);
			$dom.removeClass('item-highlight');
		},
		savePlateAdd: function(id, codelist, $dom) {
			var self = this;
			if ($.isArray(codelist)) {
				codelist = codelist.join(',');
			}
			plateListModel.requestAdd(id, codelist, function(num) {

				if ($dom) {
					if (num >= 600 && 　$dom.attr('data-type') === 'optional') {
						self.showtip("自选股上限为600个!");
					} else if (num >= 300 && 　$dom.attr('data-type') !== 'optional') {
						self.showtip("板块股上限为300个!");
					} else {
						self.showtip("添加成功");
					}
					var $num = $dom.find('.num');
					$num.hide().addClass('new').text('(' + num + ')').fadeIn();
					setTimeout(function() {
						$num.fadeOut().removeClass('new').fadeIn('fast');
					}, 2000);
				}
			});
		},
		// 板块操作提示
		showtip: function(content) {
			$('#sidebar-tipbox').text(content);
			$('#sidebar-tipbox').fadeIn('fast');
			setTimeout(function() {
				$('#sidebar-tipbox').fadeOut();
			}, 1000);
		},
		//输入框闪烁两次
		flash: function(count, intervalTime) {
			//alert(23)
			count = count || 2;
			intervalTime = intervalTime || 300;
			var time = 0;
			var searchBox = $('#view_div_searchbox');
			var searchBtn = $('#view_searchbtn');
			$('#view_searchinput').focusEnd();

			var timer = setInterval(function() {
				if (time >= count + 1) {
					clearInterval(timer);
				}
				if (time % 2 === 1) {
					searchBox.addClass('searchbox-focus');
					searchBtn.addClass('searchbtn-focus');
				} else {
					searchBox.removeClass('searchbox-focus');
					searchBtn.removeClass('searchbtn-focus');
				}

				time++;
			}, intervalTime);
		},
		/**
		 * 获得url中的参数
		 * @param  {[string]} name [参数名称]
		 * @return {[string]}      [返回参数的值]
		 */
		getQuery: function(name) {
			var href = window.location.href;
			href = decodeURIComponent(href);
			var reg = new RegExp("(^|&|\\?)" + name + "=([^&]*)(&|$)"),
				r;
			if (r = href.match(reg)) {
				return unescape(r[2]).replace('###','').replace('#','');
			}
			return undefined;
		},
		changeTitle: function(name, callback) {
			var self = this;
			var title = $('#moveDom').find('.title-span');
			title.text(name);
			//预留一个接口,可以设置改变title后再做点其他事情
			if (callback) {
				callback();
			}
		},

		deletePlateStock:function(plateid,code){
			try{
				var Util = external.createObject('Util');
				Util.deleteCustomBlockStock(plateid,code);
				CodeListModel.removeCodeList(code);
				
			}catch(e){}

		},
		//小搜索框闪烁两次
		singleFlash: function(count, intervalTime) {
			count = count || 2;
			intervalTime = intervalTime || 300;
			var time = 0;
			var searchBox = $('.win-input');
			//var searchBtn = $('#view_searchbtn');

			var timer = setInterval(function() {
				if (time >= count + 1) {
					clearInterval(timer);
				}
				if (time % 2 === 0) {
					searchBox.addClass('searchbox-focus');
					//searchBtn.addClass('searchbtn-focus');
				} else {
					searchBox.removeClass('search-focus');
					//searchBtn.removeClass('searchbtn-focus');
				}

				time++;
			}, intervalTime);
			timer();
		},
		renderScrollSlider: function () {
			$('#sidebarbox').slimScroll({
				width: '177px',
				height: '100%',
				alwaysVisible: true,
				disableFadeOut: false,
				borderRadius: 0,
				scrollTo: '0'
			});
		},
		renderScrollTable: function () {
			$('.result-table').slimScroll({
				height: '355px',
				width: '515px',
				alwaysVisible: true,
				disableFadeOut: false,
				borderRadius: 0,
				scrollTop: '0'
			});
		},
		renderScrollOption: function () {
			$('#view_select_option').slimScroll({
				height: '220px',
				width: '100px',
				alwaysVisible: true,
				disableFadeOut: false,
				borderRadius: 0,
				scrollTo: '0'
			});
		}
	});
	module.exports = BaseView;
});
